package main

import (
	"log"
	"reflect"
)

type Person struct {
	Name string
	Age  int
}

type Student struct {
	Person
	StudentId  int
	SchoolName string
	IsBaosong  bool
	Hobbies    []string
	hobbies    []string
	Labels     map[string]string
}

func (s *Student) GoHome() {
	log.Printf("[go home][sid:%d]", s.StudentId)
}

func (s Student) GotoSchool() {
	log.Printf("[go to school][sid:%d]", s.StudentId)
}

func (s Student) Baosong() {
	log.Printf("[baosong sheng][sid:%d]", s.StudentId)
}

func main() {
	s := Student{
		Person:     Person{Name: "lwq", Age: 18},
		StudentId:  00123,
		SchoolName: "collage",
		IsBaosong:  false,
		Hobbies:    []string{"chang", "tiao", "rap", "drive"},
		hobbies:    nil,
		Labels:     map[string]string{"k1": "v1", "k2": "v2"},
	}
	t := reflect.TypeOf(s)
	log.Printf("[obj name:%s]", t.Name())

	v := reflect.ValueOf(s)
	for i := 0; i < t.NumField(); i++ {
		key := t.Field(i)
		value := v.Field(i)
		if key.Anonymous {
			log.Printf("[anonymous field][%dfield][field name:%s][field type:%v][field value:%v]", i+1, key.Name, key.Type, value)
		} else {
			log.Printf("[name field][%dfield][field name:%s][field type:%v][field value:%v]", i+1, key.Name, key.Type, value)
		}
	}

	for i := 0; i < t.NumMethod(); i++ {
		m := t.Method(i)
		log.Printf("[method field][%dfield][method name:%s][method type:%v]", i+1, m.Name, m.Type)
	}
}
